function checkFrm() {
    $("#submitBtn").html("正在提交...");
    $("#submitBtn").addClass("layui-btn-disabled");
}
var optionTmp = {
    type: "post",
    dataType: "json",
    beforeSubmit: checkFrm,
    url: doAddUrl,
    success: function (data) {
        dialog.alert(data.msg);
        if (data.flag) {
            //window.location.href = listUrl;
            setTimeout(function () {
                window.parent.location.reload();
            }, 1000);

        } else {
            $("#submitBtn").html("确定提交");
            $("#submitBtn").removeClass("layui-btn-disabled");
        }
    },
    error: function () {
        dialog.alert("接口异常");
        $("#submitBtn").html("确定提交");
        $("#submitBtn").removeClass("layui-btn-disabled");
    }
};

$("#submitBtn").click(function () {
    $("#addFrm").ajaxSubmit(optionTmp);
});

function changeKehuCustom(custom_id, frm) {

    if (custom_id > 0) {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: getCustomAddressUrl,
            data: {
                custom_id: custom_id
                , type_id: 1
            },
            success: function (data) {
                var optionStr = "<option value=''>请选择</option>";
                for (var i in data) {
                    optionStr += "<option value = '" + data[i].id + "'>" + data[i].p_name + "/" + data[i].c_name + (data[i].d_name != "" ? "/" + data[i].d_name : "") + (data[i].address != "" ? "/" + data[i].address : "") + "</option>";
                }
                optionStr += "<option value='-1'>+新增地址</option>";
                $("select[name=org_id]").html(optionStr);
                frm.render('select'); //刷新select选择框渲染
            }
        });
        $.ajax({
            type: "GET",
            dataType: "json",
            url: getCustomAddressUrl,
            data: {
                custom_id: custom_id
                , type_id: 2
            },
            success: function (data) {
                var optionStr2 = "<option value=''>请选择</option>";
                for (var i in data) {
                    optionStr2 += "<option value = '" + data[i].id + "'>" + data[i].p_name + "/" + data[i].c_name + "/" + data[i].d_name + "/" + data[i].address + "</option>";
                }
                optionStr2 += "<option value='-1'>+新增地址</option>";
                $("select[name=dest_id]").html(optionStr2);
                frm.render('select'); //刷新select选择框渲染
            }
        });

    } else {
        var optionStr = "<option value=''>请选择</option>";
        var optionStr2 = "<option value=''>请选择</option>";
        optionStr += "<option value='-1'>+新增地址</option>";
        optionStr2 += "<option value='-1'>+新增地址</option>";
        $("select[name=org_id]").html(optionStr);
        $("select[name=dest_id]").html(optionStr2);
        frm.render('select'); //刷新select选择框渲染
    }
}

function getOrg(custom_id, org_id, frm) {
    $.ajax({
        type: "GET",
        dataType: "json",
        url: getCustomAddressUrl,
        data: {
            custom_id: custom_id,
            type_id: 1
        },
        success: function (data) {
            var optionStr = "<option value=''>请选择</option>";
            for (var i in data) {
                optionStr = optionStr + "<option value = '" + data[i].id + "'" + (org_id == data[i].id ? " selected" : "") + ">" + data[i].p_name + "/" + data[i].c_name + "/" + data[i].d_name + "/" + data[i].address + "</option>";
            }
            optionStr += "<option value='-1'>+新增地址</option>";
            $("select[name='org_id']").html(optionStr);
            frm.render('select'); //刷新select选择框渲染
        }
    });
}

function getDest(custom_id, dest_id, frm) {
    $.ajax({
        type: "GET",
        dataType: "json",
        url: getCustomAddressUrl,
        data: {
            custom_id: custom_id,
            type_id: 2
        },
        success: function (data) {
            var optionStr = "<option value=''>请选择</option>";
            for (var i in data) {
                optionStr = optionStr + "<option value = '" + data[i].id + "'" + (dest_id == data[i].id ? " selected" : "") + ">" + data[i].p_name + "/" + data[i].c_name + "/" + data[i].d_name + "/" + data[i].address + "</option>";
            }
            optionStr += "<option value='-1'>+新增地址</option>";
            $("select[name='dest_id']").html(optionStr);
            frm.render('select'); //刷新select选择框渲染
        }
    });
}